Server 同步 gitLab


Posted by 半夏 on 2021-08-25

cPanel 自動同步 GitLab 檔案

php 的方式

Cron job 指令

php -q /home/.../public_html/git.php >/dev/null 2>&1

檔案 git.php

<?php 
    shell_exec( 'git pull origin master' );
    echo '同步完成!';
?>

git.sh 的方式

Cron job 指令

/home/.../git.sh >/dev/null 2>&1

檔案 git.sh

cd /home/.../public_html/資料夾名稱

git checkout -b branch-name
git remote update

UPSTREAM=${1:-'@{u}'}
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse "$UPSTREAM")
BASE=$(git merge-base @ "$UPSTREAM")

if [ $LOCAL = $REMOTE ]; then
    echo "Up-to-date"
elif [ $LOCAL = $BASE ]; then
    echo "Need to pull"
    git pull origin branch-name
fi









Related Posts

篩選方法- map( ), filter( ), find( ), some( )

篩選方法- map( ), filter( ), find( ), some( )

簡明人月神話:專案管理之道(The Mythical Man-Month)導讀書摘

簡明人月神話:專案管理之道(The Mythical Man-Month)導讀書摘

[ CSS 03 ]  盒模型(box model)與定位(position)

[ CSS 03 ] 盒模型(box model)與定位(position)


Comments